from tortoise.models import Model
from tortoise import fields
from enum import Enum
from pydantic import BaseModel, Field, validator
from typing import Optional

class RoleEnum(str, Enum):
    student = "student"
    teacher = "teacher"
    admin = "admin"

class Student(Model):
    stu_id = fields.IntField(pk=True)
    username = fields.CharField(max_length=50, unique=True)
    password = fields.CharField(max_length=100)
    head = fields.BinaryField(null=True)
    gender = fields.CharField(max_length=10, null=True)
    content = fields.TextField(null=True)
    role = fields.CharEnumField(RoleEnum, default=RoleEnum.student)

    # 多对多关系（关键修改：完全移除ManyToManyField定义）
    # 注意：这里不再定义ManyToManyField，关系完全通过Record中间表管理
    class Meta:
        table = "students"
    class Config:
        from_attributes = True